/*
 * Created by JFormDesigner on Fri Jun 19 17:17:20 BST 2009
 */

package gui;

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.*;

import execution.Manager;

import resources.Logger;

/**
 * @author Alexandros Ouzounis
 */
public class WindowMain extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3474598007464665856L;
	private int progressValue = 0;
	private Manager manager;

	public WindowMain(Manager m) {
		initComponents();
		manager = m;
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY
		// //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Evaluation license - Alexandros
		// Ouzounis
		menuBar = new JMenuBar();
		menuFile = new JMenu();
		menuItemNewProject = new JMenuItem();
		// menuItemOpenProject = new JMenuItem();
		// menuItemSaveProject = new JMenuItem();
		menuItemSettings = new JMenuItem();
		menuItemQuit = new JMenuItem();
		menuLoad = new JMenu();
		menuItemPDF = new JMenuItem();
		menudatabase = new JMenu();
		menuItemCategories = new JMenuItem();
		menuItemRecords = new JMenuItem();
		menuMine = new JMenu();
		menuItemSelectFieldsToMine = new JMenuItem();
		menuItemViewResults = new JMenuItem();
		menuHelp = new JMenu();
		menuItemDocumentation = new JMenuItem();
		menuItemAboutDataMiner = new JMenuItem();
		panel1 = new JPanel();
		labelStatus = new JLabel();
		progressBar = new JProgressBar();
		desktopPane1 = new JDesktopPane();

		// ======== this ========
		setTitle("DataMiner");
		this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		addWindowListener(new MyWindowListener());
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		// ======== menuBar ========
		{

			// ======== menuFile ========
			{
				menuFile.setText("File");

				// ---- menuItemNewProject ----
				menuItemNewProject.setText("New Project");
				menuFile.add(menuItemNewProject);
				/*
				 * //---- menuItemOpenProject ----
				 * menuItemOpenProject.setText("Open Project");
				 * menuFile.add(menuItemOpenProject);
				 */
				/*
				 * //---- menuItemSaveProject ----
				 * menuItemSaveProject.setText("Save Project");
				 * menuFile.add(menuItemSaveProject);
				 */
				// ---- menuItemSettings ----
				menuItemSettings.setText("Settings");
				menuFile.add(menuItemSettings);

				// ---- menuItemQuit ----
				menuItemQuit.setText("Quit");
				menuFile.add(menuItemQuit);
			}
			menuBar.add(menuFile);

			// ======== menuLoad ========
			{
				menuLoad.setText("Load");

				// ---- menuItemPDF ----
				menuItemPDF.setText("Load a PDF");
				menuLoad.add(menuItemPDF);
			}
			menuBar.add(menuLoad);

			// ======== menudatabase ========
			{
				menudatabase.setText("Database");

				// ---- menuItemCategories ----
				menuItemCategories.setText("View Categories");
				menudatabase.add(menuItemCategories);

				// ---- menuItemRecords ----
				menuItemRecords.setText("View Records");
				menudatabase.add(menuItemRecords);
			}
			menuBar.add(menudatabase);

			// ======== menuMine ========
			{
				menuMine.setText("Mine");

				// ---- menuItemSelectFieldsToMine ----
				menuItemSelectFieldsToMine.setText("Select Fields To Mine");
				menuMine.add(menuItemSelectFieldsToMine);

				// ---- menuItemViewResults ----
				menuItemViewResults.setText("View Mine Results");
				menuMine.add(menuItemViewResults);
			}
			menuBar.add(menuMine);

			// ======== menuHelp ========
			{
				menuHelp.setText("Help");

				// ---- menuItemDocumentation ----
				menuItemDocumentation.setText("View documentation");
				menuHelp.add(menuItemDocumentation);

				// ---- menuItemAboutDataMiner ----
				menuItemAboutDataMiner.setText("About Dataminer");
				menuHelp.add(menuItemAboutDataMiner);
			}
			menuBar.add(menuHelp);
		}
		setJMenuBar(menuBar);

		// ======== panel1 ========
		{

			panel1.setLayout(new GridLayout(1, 2));

			// ---- labelStatus ----
			labelStatus.setText("text");
			panel1.add(labelStatus);
			panel1.add(progressBar);
		}
		contentPane.add(panel1, BorderLayout.SOUTH);
		contentPane.add(desktopPane1, BorderLayout.CENTER);
		setLocationRelativeTo(getParent());
		// //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY
	// //GEN-BEGIN:variables
	// Generated using JFormDesigner Evaluation license - Alexandros Ouzounis
	private JMenuBar menuBar;
	private JMenu menuFile;
	private JMenuItem menuItemNewProject;
	// private JMenuItem menuItemOpenProject;
	// private JMenuItem menuItemSaveProject;
	private JMenuItem menuItemSettings;
	private JMenuItem menuItemQuit;
	private JMenu menuLoad;
	public JMenuItem menuItemPDF;
	private JMenu menudatabase;
	private JMenuItem menuItemCategories;
	private JMenuItem menuItemRecords;
	private JMenu menuMine;
	private JMenuItem menuItemSelectFieldsToMine;
	private JMenuItem menuItemViewResults;
	private JMenu menuHelp;
	private JMenuItem menuItemDocumentation;
	private JMenuItem menuItemAboutDataMiner;
	private JPanel panel1;
	private JLabel labelStatus;
	public JProgressBar progressBar;
	public JDesktopPane desktopPane1;

	// JFormDesigner - End of variables declaration //GEN-END:variables

	// method to add messages in the status box
	public void addStatusMessage(String l) {
		labelStatus.setText(l);
		Logger.getInstance().addToLog(l);
	}

	// create the menu listeners so that the manager can access them

	public void menuNewProjectActionPerformed(ActionListener e) {
		menuItemNewProject.addActionListener(e);
	}

	/*
	 * public void menuOpenProjectActionPerformed(ActionListener e) {
	 * menuItemOpenProject.addActionListener(e); }
	 */
	/*
	 * public void menuSaveProjectActionPerformed(ActionListener e) {
	 * menuItemSaveProject.addActionListener(e); }
	 */
	public void menuSettingsActionPerformed(ActionListener e) {
		menuItemSettings.addActionListener(e);
	}

	public void menuQuitActionPerformed(ActionListener e) {
		menuItemQuit.addActionListener(e);
	}

	public void menuNewQuitActionPerformed(ActionListener e) {
		menuItemQuit.addActionListener(e);
	}

	public void menuPDFActionPerformed(ActionListener e) {
		menuItemPDF.addActionListener(e);
	}

	public void menuCategoriesActionPerformed(ActionListener e) {
		menuItemCategories.addActionListener(e);
	}

	public void menuRecordsActionPerformed(ActionListener e) {
		menuItemRecords.addActionListener(e);
	}

	public void menuSelectFieldsToMineActionPerformed(ActionListener e) {
		menuItemSelectFieldsToMine.addActionListener(e);
	}

	public void menuViewResultsActionPerformed(ActionListener e) {
		menuItemViewResults.addActionListener(e);
	}

	public void menuDocumentationActionPerformed(ActionListener e) {
		menuItemDocumentation.addActionListener(e);
	}

	public void menuAboutDataMinerActionPerformed(ActionListener e) {
		menuItemAboutDataMiner.addActionListener(e);
	}

	// create menu states

	public void menuNewProjectState() {
		// file menu
		menuItemNewProject.setEnabled(true);
		// menuItemOpenProject.setEnabled(true);
		// menuItemSaveProject.setEnabled(true);
		menuItemSettings.setEnabled(true);
		// load menu
		menuItemPDF.setEnabled(true);
		// database menu
		menuItemCategories.setEnabled(false);
		menuItemRecords.setEnabled(false);
		// mine menu
		menuItemSelectFieldsToMine.setEnabled(false);
		menuItemViewResults.setEnabled(false);
		// help menu
		menuItemDocumentation.setEnabled(true);
		menuItemAboutDataMiner.setEnabled(true);
	}

	public void menuLoadingDBState() {
		// file menu
		menuItemNewProject.setEnabled(false);
		// menuItemOpenProject.setEnabled(false);
		// menuItemSaveProject.setEnabled(false);
		menuItemSettings.setEnabled(false);
		// load menu
		menuItemPDF.setEnabled(false);
		// database menu
		menuItemCategories.setEnabled(false);
		menuItemRecords.setEnabled(false);
		// mine menu
		menuItemSelectFieldsToMine.setEnabled(false);
		menuItemViewResults.setEnabled(false);
		// help menu
		menuItemDocumentation.setEnabled(true);
		menuItemAboutDataMiner.setEnabled(true);
	}

	public void menuLoadedDBState() {
		// file menu
		menuItemNewProject.setEnabled(true);
		// menuItemOpenProject.setEnabled(true);
		// menuItemSaveProject.setEnabled(true);
		menuItemSettings.setEnabled(true);
		// load menu
		menuItemPDF.setEnabled(true);
		// database menu
		menuItemCategories.setEnabled(true);
		menuItemRecords.setEnabled(true);
		// mine menu
		menuItemSelectFieldsToMine.setEnabled(true);
		menuItemViewResults.setEnabled(false);
		// help menu
		menuItemDocumentation.setEnabled(true);
		menuItemAboutDataMiner.setEnabled(true);
	}

	public void menuMiningState() {
		// file menu
		menuItemNewProject.setEnabled(false);
		// menuItemOpenProject.setEnabled(false);
		// menuItemSaveProject.setEnabled(false);
		menuItemSettings.setEnabled(false);
		// load menu
		menuItemPDF.setEnabled(false);
		// database menu
		menuItemCategories.setEnabled(true);
		menuItemRecords.setEnabled(true);
		// mine menu
		menuItemSelectFieldsToMine.setEnabled(false);
		menuItemViewResults.setEnabled(true);
		// help menu
		menuItemDocumentation.setEnabled(true);
		menuItemAboutDataMiner.setEnabled(true);

	}

	public void menuMinedState() {
		// file menu
		menuItemNewProject.setEnabled(true);
		// menuItemOpenProject.setEnabled(true);
		// menuItemSaveProject.setEnabled(true);
		menuItemSettings.setEnabled(true);
		// load menu
		menuItemPDF.setEnabled(true);
		// database menu
		menuItemCategories.setEnabled(true);
		menuItemRecords.setEnabled(true);
		// mine menu
		menuItemSelectFieldsToMine.setEnabled(true);
		menuItemViewResults.setEnabled(true);
		// help menu
		menuItemDocumentation.setEnabled(true);
		menuItemAboutDataMiner.setEnabled(true);
	}

	public void updateStatus() {
		progressValue++;
		progressBar.setValue(progressValue);
	}

	public void resetStatus() {
		progressValue = 0;
	}

	class MyWindowListener implements WindowListener {

		public void windowClosing(WindowEvent arg0) {
			manager.quit();
		}

		public void windowOpened(WindowEvent arg0) {
		}

		public void windowClosed(WindowEvent arg0) {
			manager.quit();
		}

		public void windowIconified(WindowEvent arg0) {
		}

		public void windowDeiconified(WindowEvent arg0) {
		}

		public void windowActivated(WindowEvent arg0) {
		}

		public void windowDeactivated(WindowEvent arg0) {
		}

	}

}
